#ifndef _QY_THRAED_QUEUE_H
#define _QY_THREAD_QUEUE_H

#include <queue>
#include <list>
#include "Thread.h"
//#include <tr1/boost_shared_ptr.h>

class Event;

namespace qy
{

class ThreadQueue : public Thread
{
public:
    ThreadQueue(int conThreadCount);
	virtual ~ThreadQueue();

    //The argument should be a smart pointer, such as boost_shared_ptr<Thread>
	void addThread(Thread *pThread);

protected:
    int run();

private:
    int m_conThreadCount;	//maximum count of concurrent threads
	std::list<Thread*> m_workingThreads;
	std::queue<Thread*> m_waitingThreads;
    pthread_mutex_t m_threadsMutex; //mutex for m_threads
	Event *m_loopEvent;
};

}
#endif
